#ifndef BMC_PLATFORM_LIBRARY_H__
#define BMC_PLATFORM_LIBRARY_H__
/*
   GPL
   Free soft,no warranted
   We are all in the mud, but some of us are looking at the stars.
   We are not born for ourselves.
   */
/**
 * @file platform_library_speific.h
 * @Synopsis  library operator
 * @author Chai JunJun
 * @date 2009-06-17
 */
//#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <tlpr/tltypes.h>
#include <string>
#include <locale>
#include <cstring>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>

using std::string;
using std::wstring;

/**
 * @def TL_DECL(type)
 * @param type The return type of the function.
 * Declare a function.
 */
#if defined(TL_DLL)
#   if defined(TL_EXPORTING)
#   define TL_DECL(type)        TL_EXPORT_DECL_SPECIFIER type
#   else
#   define TL_DECL(type)        TL_IMPORT_DECL_SPECIFIER type
#   endif
#elif !defined(TL_DECL)
#   if defined(__cplusplus)
#   define TL_DECL(type)        type
#   else
#   define TL_DECL(type)        extern type
#   endif
#endif

#ifdef IS_LINUX
#include <tlpr/linux_library_speific.h>
#endif

#ifdef IS_WIN32
#include <tlpr/win32_library_speific.h>
#endif

/* -------------------------------------------------------------------------- */
/** @Synopsis  ws2s convert wstring to string
 *
 * @Param ws
 *
 * @Returns
 */
/* ---------------------------------------------------------------------------- */

TL_INLINE_SPECIFIER string ws2s(const wstring& ws)
{
    string curLocale = setlocale(LC_ALL, NULL);        // curLocale = "C";

    setlocale(LC_ALL, "chs");

    const wchar_t* _Source = ws.c_str();
    size_t _Dsize = 2 * ws.size() + 1;
    char *_Dest = new char[_Dsize];
    memset(_Dest,0,_Dsize);
    wcstombs(_Dest,_Source,_Dsize);
    string result = _Dest;
    delete []_Dest;

    setlocale(LC_ALL, curLocale.c_str());

    return result;
}

/* -------------------------------------------------------------------------- */
/** @Synopsis  s2ws convert string to wstring
 *
 * @Param s
 *
 * @Returns
 */
/* ---------------------------------------------------------------------------- */

TL_INLINE_SPECIFIER wstring s2ws(const string& s)
{
    setlocale(LC_ALL, "chs");
    const char* _Source = s.c_str();
    size_t _Dsize = s.size() + 1;
    wchar_t *_Dest = new wchar_t[_Dsize];
    wmemset(_Dest, 0, _Dsize);
	mbstowcs(_Dest, _Source, _Dsize);
    wstring result = _Dest;
    delete []_Dest;

    setlocale(LC_ALL, "C");

    return result;
}

#endif //BMC_PLATFORM_LIBRARY_H__
